package gui.mainWindow.scores;

import java.awt.Color;
import java.awt.Component;

import javax.swing.BorderFactory;
import javax.swing.JLabel;
import javax.swing.JTable;
import javax.swing.border.Border;
import javax.swing.table.DefaultTableCellRenderer;

public class ScoresTableModelRenderer extends DefaultTableCellRenderer {

	private final Color semiBackground = new Color(179, 198, 255);

	public ScoresTableModelRenderer() {
		super();
	}

	@Override
	public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
		// Label erzeugen
		JLabel label;
		if (value != null) {
			label = new JLabel(value.toString());
		} else {
			label = new JLabel("0");
		}

		label.setOpaque(true);
		Border b = BorderFactory.createEmptyBorder(1, 1, 1, 1);
		label.setBorder(b);
		label.setFont(table.getFont());
		label.setForeground(table.getForeground());
		label.setBackground(table.getBackground());

		// Angezeigte Zeile in ModellZeile umwandeln
		row = table.convertRowIndexToModel(row);

		if (row == table.getRowCount() - 1) {
			label.setBackground(Color.BLACK);
			label.setForeground(Color.WHITE);
		}

		if (hasFocus) {
			label.setBackground(Color.gray);
			label.setForeground(Color.black);
		} else if (isSelected) {
			label.setBackground(Color.white);
			label.setForeground(Color.black);
		}
		return label;
	}
}
